//
//  SDWebImageExample.swift
//  SwiftCode
//
//  Created by yuhus on 2023/7/17.
//

import Foundation
import UIKit
import SDWebImage

final class SDWebImageExample: ListViewController {
  override func getItemCount() -> Int {
    data.count
  }
  
  override func getItem(_ indexPath: IndexPath) -> Item {
    data[indexPath.row]
  }
  
  private lazy var data: [Item] = [
    .init(title: "setImage", description: "显示一个图片", action: { [weak self] in self?.setImage() }),
    
  ]
  
  private func setImage() {
    imageView.sd_setImage(with: URL(string: WebUrl.webP[0]), placeholderImage: UIImage(named: "placeholder.png")) {_,_,_,_ in
      
    }
    _ = NSData(data: Data())
    let can = SDImageIOCoder.shared.canDecode(from: nil)
    let image = SDImageIOCoder.shared.decodedImage(with: nil)
    
  }
    
  override func viewDidLoad() {
    super.viewDidLoad()
    
    view.addSubview(imageView)
    imageView.snp.makeConstraints { make in
      make.size.equalTo(200)
      make.center.equalToSuperview()
    }
  }
  
  private lazy var imageView: UIImageView = {
    let view = UIImageView()
    view.backgroundColor = .red
    view.layer.cornerRadius = 8
    view.layer.masksToBounds = true
    return view
  }()
}

enum WebUrl {
  static let jpeg = [
    "https://pics7.baidu.com/feed/060828381f30e924ba20b9e08ac42d0d1f95f7b6.jpeg",
    "https://pics5.baidu.com/feed/0b46f21fbe096b63d499794fc3ffc44feaf8ac00.jpeg"
  ]
  static let png = [
    "https://pics0.baidu.com/feed/9a504fc2d56285358efaed165f2335cda6ef63c2.png",
    "https://pics7.baidu.com/feed/77094b36acaf2edd3719abf544dc42e23801931e.png",
    "https://pics2.baidu.com/feed/d53f8794a4c27d1e3d02d453dd19ee65dcc4385d.png",
    "https://pics2.baidu.com/feed/d53f8794a4c27d1e3d02d453dd19ee65dcc4385d.png"
    
  ]
  static let gif = [
    "https://pic.rmb.bdstatic.com/bjh/a232da4fdc1bef046d2b27f4170f123d7187.gif",
    "https://pic.rmb.bdstatic.com/bjh/cfd607ac6180935e8cf6b95cef2bb9a92695.gif",
  ]
  static let webP = [
    "https://check-basic-content.metaworld.fun/pre/meta-ugc-game-repository-center/bce49b81b4f543279ce686901b674958.webp",
    "https://check-basic-content.metaworld.fun/pre/meta-ugc-game-repository-center/10ec016592f34bb38ecc13ed6a18ec1c.webp",
    "https://check-basic-content.metaworld.fun/pre/meta-ugc-game-repository-center/4d4f17d7e60e4a1fa1437cfa36410ad4.webp",
    "https://check-basic-content.metaworld.fun/pre/meta-ugc-game-repository-center/5f84564514704850894e5b74ef4e8c4d.webp",
    "https://check-basic-content.metaworld.fun/pre/meta-ugc-game-repository-center/d1472e0865fa40b7860221952690657c.webp",
    "https://check-basic-content.metaworld.fun/pre/meta-ugc-game-repository-center/97321743d8a74f46b1ce3cb800641b27.webp",
    "https://check-basic-content.metaworld.fun/pre/meta-ugc-game-repository-center/41491dcaaa94446f983d1517cd73b72e.webp",
    "https://check-basic-content.metaworld.fun/pre/meta-ugc-game-repository-center/ca47f2baf91e4f388a7ca3f967d7d014.webp",
    "https://check-basic-content.metaworld.fun/pre/meta-ugc-game-repository-center/1fc37b9727304e20a1d66e2cabc04885.webp",
    "https://check-basic-content.metaworld.fun/pre/meta-ugc-game-repository-center/0c976ae90048463789347fc2244c5b1d.webp",
  ]
}
